package com.base.controller;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beust.jcommander.internal.Lists;
import com.base.po.param.NetState;
import com.base.utils.Redis.RedisUtil;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.base.comm.CommExcel;
import com.base.po.voip.SelfShop;
import com.base.po.voip.SelfShopCategory;
import com.base.po.voip.SelfShopCoupon;
import com.base.po.voip.SelfShopGoods;
import com.base.po.voip.Subscribers;
import com.base.po.voip.Users;
import com.base.service.SelfShopCategoryService;
import com.base.service.SelfShopCouponService;
import com.base.service.SelfShopGoodsService;
import com.base.service.SelfShopService;
import com.base.service.UsersService;
import com.base.utils.Page;
import com.base.utils.Produce;

/**
 * 自营商城
 *
 * @author Administrator
 */
@Controller
@RequestMapping("/admin")
public class index_SelfShopGoods {
    @Autowired
    private SelfShopService selfShopService;
    @Autowired
    private SelfShopGoodsService selfShopGoodsService;
    @Autowired
    private SelfShopCategoryService selfShopCategoryService;
    @Autowired
    private SelfShopCouponService selfShopCouponService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private RedisUtil redisCacheManager;

    // 自营商城分类首页
    @RequestMapping("/selfShopGoods")
    public ModelAndView index(HttpServletRequest request) throws Exception {
        // 返回ModelAndView
        ModelAndView modelAndView = new ModelAndView();
        String adminUserId = (String) request.getSession().getAttribute("adminUserId");
//		Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
        Page page = new Page();
        Users users = usersService.selectByPrimaryKey(adminUserId);
        List<SelfShop> selfShops = null;
        SelfShop selfShop = null;
        if (users.getRole() == 0 || users.getRole() == 1) {
            selfShops = selfShopService.selectBySelfShop(adminUserId, adminUserId);
            if (selfShops != null && selfShops.size() > 0) {
                selfShop = selfShops.get(0);
            }
        }
        if (users.getRole() == 2) {
            selfShops = selfShopService.selectBySelfShop(users.getParentid(), adminUserId);
            if (selfShops != null && selfShops.size() > 0) {
                selfShop = selfShops.get(0);
            }
        }

        //已有一级分类
        List<SelfShopCategory> selfShopCategory = null;
        if (users.getRole() == 0 || users.getRole() == 1) {
            selfShopCategory = selfShopCategoryService.selectByLevel1(adminUserId, adminUserId);
        }
        if (users.getRole() == 2) {
            selfShopCategory = selfShopCategoryService.selectByLevel1(users.getParentid(), users.getParentid());
        }

        //已有商品
        List<SelfShopGoods> selfShopGoods = null;
        page.setCurrentPageNo(1);
        if (users.getRole() == 0 || users.getRole() == 1) {
            page.setRecordTotal(selfShopGoodsService.countByAll(adminUserId, adminUserId, null, null, null, null));
            selfShopGoods = selfShopGoodsService.selectByAll(page, adminUserId, adminUserId, null, null, null, null);
        }
        if (users.getRole() == 2) {
            page.setRecordTotal(selfShopGoodsService.countByAll(users.getParentid(), adminUserId, null, null, null, null));
            selfShopGoods = selfShopGoodsService.selectByAll(page, users.getParentid(), adminUserId, null, null, null, null);
        }

        if (selfShopGoods != null && selfShopGoods.size() > 0) {
            for (SelfShopGoods s : selfShopGoods) {
                if (s.getFirstclassify() != null) {
                    if (s.getFirstclassify().equals("农机") || s.getFirstclassify().equals("农药") ||
                            s.getFirstclassify().equals("种子") || s.getFirstclassify().equals("化肥")) {

                    } else {
                        try {
                            s.setFirstclassify(selfShopCategoryService
                                    .selectByPrimaryKey(s.getFirstclassify()).getCategory());
                        } catch (Exception e) {
                            s.setFirstclassify("未查询到分类");
                        }
                    }
                } else {
                    s.setFirstclassify("未知一级分类");
                }

                if (s.getSecondclassify() != null) {
                    s.setSecondclassify(selfShopCategoryService
                            .selectByPrimaryKey(s.getSecondclassify()).getCategory());
                } else {
                    s.setSecondclassify("未知二级分类");
                }
            }

            request.setAttribute("selfShopGoods", selfShopGoods);
        }
        if (selfShopCategory != null && selfShopCategory.size() > 0) {
            request.setAttribute("selfShopCategory", selfShopCategory);
        }
        request.setAttribute("selfShop", selfShop);
        request.setAttribute("totlenum", page.getRecordTotal());// 传入session中
        request.setAttribute("curPage", page.getCurrentPageNo());// 传入session中
        request.setAttribute("firstclassify", "一级分类");
        request.setAttribute("secondclassify", "二级分类");
        request.setAttribute("status", 3);
        CommExcel.couponList.clear();
        // 设置页面进行跳转
        modelAndView.setViewName("jsp/index_SelfShopGoods");
        return modelAndView;
    }

    @RequestMapping("/selectSelfShopGoods")
    public ModelAndView selectSelfShopGoods(HttpServletRequest request, Integer curPage, String goodstext,
                                            String firstclassify, String secondclassify, Byte status) throws Exception {
        // 设置session缓存
        if (curPage == null) {
            if (request.getSession().getAttribute("curPage") != null) {
                curPage = (Integer) request.getSession().getAttribute("curPage");
            } else {
                curPage = 1;
            }
        }
//		Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
        String adminUserId = (String) request.getSession().getAttribute("adminUserId");

        ModelAndView modelAndView = new ModelAndView();
        Page page = new Page();
        Users users = usersService.selectByPrimaryKey(adminUserId);

        List<SelfShop> selfShops = null;
        SelfShop selfShop = null;
        if (users.getRole() == 0 || users.getRole() == 1) {
            selfShops = selfShopService.selectBySelfShop(adminUserId, adminUserId);
            if (selfShops != null && selfShops.size() > 0) {
                selfShop = selfShops.get(0);
            }
        }
        if (users.getRole() == 2) {
            selfShops = selfShopService.selectBySelfShop(users.getParentid(), adminUserId);
            if (selfShops != null && selfShops.size() > 0) {
                selfShop = selfShops.get(0);
            }
        }

        //已有分类
        List<SelfShopCategory> selfShopCategory = null;
        if (users.getRole() == 0 || users.getRole() == 1) {
            selfShopCategory = selfShopCategoryService.selectByLevel1(adminUserId, adminUserId);
        }
        if (users.getRole() == 2) {
            selfShopCategory = selfShopCategoryService.selectByLevel1(users.getParentid(), users.getParentid());
        }

        //已有商品
        List<SelfShopGoods> selfShopGoods = null;
        Integer choose = 2;
        if (goodstext != null && !goodstext.equals("") || !firstclassify.equals("分类") || status != 3) {
            choose = 1;
        }

        String fGoodsText = null;
        String fFirstClassify = null;
        String fSecondClassify = null;
        Byte fStatus = null;

        if (goodstext != null && !goodstext.equals("")) {
            fGoodsText = goodstext;
        }
        if (!firstclassify.equals("一级分类")) {
            fFirstClassify = firstclassify;
        }
        if (!secondclassify.equals("二级分类")) {
            fSecondClassify = secondclassify;
        }
        if (status != 3) {
            fStatus = status;
        }

        page.setCurrentPageNo(curPage);
        if (users.getRole() == 0 || users.getRole() == 1) {
            page.setRecordTotal(selfShopGoodsService.countByAll(adminUserId, adminUserId, fGoodsText, fFirstClassify, fSecondClassify,
                    fStatus));
            selfShopGoods = selfShopGoodsService.selectByAll(page, adminUserId, adminUserId, fGoodsText, fFirstClassify, fSecondClassify,
                    fStatus);
        }
        if (users.getRole() == 2) {
            page.setRecordTotal(selfShopGoodsService.countByAll(users.getParentid(), adminUserId, fGoodsText, fFirstClassify, fSecondClassify,
                    fStatus));
            selfShopGoods = selfShopGoodsService.selectByAll(page, users.getParentid(), adminUserId, fGoodsText, fFirstClassify, fSecondClassify,
                    fStatus);
        }

        if (choose == 2) {
            if (users.getRole() == 0 || users.getRole() == 1) {
                page.setRecordTotal(selfShopGoodsService.countByAll(adminUserId, adminUserId, null, null, null, null));
                selfShopGoods = selfShopGoodsService.selectByAll(page, adminUserId, adminUserId, null, null, null, null);
            }
            if (users.getRole() == 2) {
                page.setRecordTotal(selfShopGoodsService.countByAll(users.getParentid(), adminUserId, null, null, null, null));
                selfShopGoods = selfShopGoodsService.selectByAll(page, users.getParentid(), adminUserId, null, null, null, null);
            }
        }

        request.setAttribute("totlenum", page.getRecordTotal()); // 分页
        request.setAttribute("curPage", page.getCurrentPageNo());// 当前页面传入session中

        if (selfShopGoods != null && selfShopGoods.size() > 0) {
            for (SelfShopGoods s : selfShopGoods) {
                if (s.getFirstclassify() != null) {
                    if (s.getFirstclassify().equals("农机") || s.getFirstclassify().equals("农药") ||
                            s.getFirstclassify().equals("种子") || s.getFirstclassify().equals("化肥")) {

                    } else {
                        try {
                            s.setFirstclassify(selfShopCategoryService
                                    .selectByPrimaryKey(s.getFirstclassify()).getCategory());
                        } catch (Exception e) {
                            s.setFirstclassify("未查询到分类");
                        }
                    }
                } else {
                    s.setFirstclassify("未知一级分类");
                }

                if (s.getSecondclassify() != null) {
                    s.setSecondclassify(selfShopCategoryService
                            .selectByPrimaryKey(s.getSecondclassify()).getCategory());
                } else {
                    s.setSecondclassify("未知二级分类");
                }
            }

            request.setAttribute("selfShopGoods", selfShopGoods);
        }
        if (selfShopCategory != null && selfShopCategory.size() > 0) {
            request.setAttribute("selfShopCategory", selfShopCategory);
        }

        CommExcel.couponList.clear();
        // 设置页面进行跳转
        modelAndView.setViewName("jsp/index_SelfShopGoods");
        request.setAttribute("selfShop", selfShop);
        request.setAttribute("firstclassify", firstclassify);
        request.setAttribute("secondclassify", secondclassify);
        request.setAttribute("status", status);
        request.setAttribute("goodstext", goodstext);
        return modelAndView;
    }

    //导入优惠券
    @RequestMapping("/couponInfo")
    private void couponInfo(HttpServletRequest request, HttpServletResponse response, String file,
                            String batch, String starttime, String endtime) throws Exception {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        PrintWriter out = response.getWriter();
        String adminId = (String) request.getSession().getAttribute("adminUserId");
        Users users = usersService.selectByPrimaryKey(adminId);
        // 查询是否创建自建商城
        List<SelfShop> selfShopList = null;
        if (users.getRole() == 0 || users.getRole() == 1) {
            selfShopList = selfShopService.selectBySelfShop(adminId, adminId);
            if (selfShopList == null || selfShopList.size() < 1) {
                selfShopService.insertSelective(new SelfShop(Produce.getUUID(), adminId,
                        adminId, Produce.getNowDate(), (byte) 1, (byte) 1, Produce.getNowDate()));
                selfShopList = selfShopService.selectBySelfShop(adminId, adminId);
            }
        }
        if (users.getRole() == 2) {
            selfShopList = selfShopService.selectBySelfShop(users.getParentid(), adminId);

        }

        // 读取Excel
        readExcel(request, response, file);

        // 查看自建商城有没有 优惠券的分类 没有创建一个
        // 自动生成优惠券分类id
        String couponCAT = Produce.getUUID();
        String couponGoods = Produce.getUUID();
        // 查询是否存在优惠券分类和优惠券商品
        if (selfShopList != null && selfShopList.size() > 0) {
            SelfShop selfShop = selfShopList.get(0);
            if (selfShop.getCouponcat() == null) {
                if (users.getRole() == 1) {
                    selfShopCategoryService.insert(new SelfShopCategory(couponCAT, adminId, adminId,
                            "优惠券", 1, null, null, 0, (byte) 1));
                }

                if (users.getRole() == 1) {
                    selfShopGoodsService.insertSelective(new SelfShopGoods(couponGoods, adminId, adminId,
                            users.getUsername() + batch + "优惠券", couponCAT, new BigDecimal(0), new BigDecimal(0),
                            (byte) 1, (byte) 1, Produce.getNowDate(), Produce.getNowDate(), (byte) 2));
                    //自建商城更新优惠券分类
                    selfShop.setCouponcat(couponCAT);
                    // 更新商城信息里的优惠券商品id
                    selfShop.setCouponcatstatus((byte) 1);
                }
                if (users.getRole() == 2) {
                    // 查询最上级代理商 自建商城信息
                    List<SelfShop> selfShops = selfShopService.selectBySelfShop(users.getParentid(), users.getParentid());
                    if (selfShops != null && selfShops.size() > 0) {
                        if (selfShops.get(0).getCouponcat() != null) {
                            selfShopGoodsService.insertSelective(new SelfShopGoods(couponGoods, users.getParentid(), adminId,
                                    users.getUsername() + batch + "优惠券", selfShops.get(0).getCouponcat(), new BigDecimal(0), new BigDecimal(0), (byte) 1, (byte) 1,
                                    Produce.getNowDate(), Produce.getNowDate(), (byte) 2));
                            //自建商城更新优惠券分类
                            selfShop.setCouponcat(selfShops.get(0).getCouponcat());
                            // 更新商城信息里的优惠券商品id
                            selfShop.setCouponcatstatus((byte) 1);
                        } else {
                            out.print("未查询到优惠券分类,无法自动生成优惠券商品，导入优惠券失败");
                            return;
                        }
                    } else {
                        System.out.println("1111");
                        out.print("未查询到代理商自建商城店铺信息");
                        return;
                    }
                }
                selfShopService.updateByPrimaryKeySelective(selfShop);
            } else {
                if (users.getRole() == 1) {
                    selfShopGoodsService.insertSelective(new SelfShopGoods(couponGoods, adminId, adminId,
                            users.getUsername() + batch + "优惠券", selfShop.getCouponcat(), new BigDecimal(0), new BigDecimal(0),
                            (byte) 1, (byte) 1, Produce.getNowDate(), Produce.getNowDate(), (byte) 2));
                }
                if (users.getRole() == 2) {
                    // 查询最上级代理商 自建商城信息
//    				List<SelfShop> selfShops = selfShopService.selectBySelfShop(users.getParentid(), users.getParentid());
//    				if(selfShops != null && selfShops.size() > 0 ) {
                    if (selfShop.getCouponcat() != null) {
                        selfShopGoodsService.insertSelective(new SelfShopGoods(couponGoods, users.getParentid(), adminId,
                                users.getUsername() + batch + "优惠券", selfShop.getCouponcat(), new BigDecimal(0), new BigDecimal(0), (byte) 1, (byte) 1,
                                Produce.getNowDate(), Produce.getNowDate(), (byte) 2));
                    } else {
                        out.print("未查询到优惠券分类,无法自动生成优惠券商品，导入优惠券失败");
                        return;
                    }
                }
//    			}
            }
        }

        insertCoupon(request, response, couponGoods, starttime, endtime);

    }

    @RequestMapping("/getALLGoodSByPaiPai")
    private @ResponseBody
    NetState getALLGoodSByPaiPai(HttpServletRequest request, HttpServletResponse response,
                                 String id, Integer status) throws IOException {
        NetState netState = new NetState();
        List<Object> reds = redisCacheManager.lGet("ALLSelfShopPaiPai", 0, 3);
        List<Object> returnObject= Lists.newArrayList();
        reds.forEach(item -> {
           SelfShopGoods selfShopGoods= selfShopGoodsService.selectByPrimaryKey(item.toString());
          if (selfShopGoods!=null){
//              selfShopService.countAllShop()
             String goodsShop= selfShopGoods.getShopid();
             selfShopGoods.setSelfShop(selfShopService.selectByPrimaryKey(goodsShop));
              returnObject.add(selfShopGoods);
          }
        });
        netState.setErrorCode(NetState.SUCCESS_CONN);
        netState.setData("请求成功");
        netState.setJson(returnObject);
        return netState;
    }

    @RequestMapping("/addgoodstoRedis")
    private void addgoodstoRedis(HttpServletRequest request, HttpServletResponse response,
                                 String id, Integer status) throws IOException {
        SelfShopGoods selfShopGoods = selfShopGoodsService.selectByPrimaryKey(id);
        if (selfShopGoods != null) {
            Boolean bol=false;
            List<Object> o= redisCacheManager.lGet("ALLSelfShopPaiPai",0,-1);
            switch (status) {
                case 1:
                   if (o!=null){
                       for (Object o1 : o) {
                           if (o1.toString().equals(id)){
                               bol=true;
                           }
                       }
                   }
                   if (!bol){
                       redisCacheManager.lSet("ALLSelfShopPaiPai", id);
                   }
                    break;
                case 2:
                    if (o!=null){
                        for (Object o1 : o) {
                            if (o1.toString().equals(id)){
                                bol=true;
                            }
                        }
                    }
                    if (bol){
                        redisCacheManager.hdel("ALLSelfShopPaiPai", id);
                    }
                    break;
            }
        }

    }

    @RequestMapping("/insertCoupon")
    private void insertCoupon(HttpServletRequest request, HttpServletResponse response, String couponGoods,
                              String starttime, String endtime) throws IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        PrintWriter out = response.getWriter();
        String adminId = (String) request.getSession().getAttribute("adminUserId");
        Users users = usersService.selectByPrimaryKey(adminId);

        String pId = null;
        if (users.getRole() == 1) {
            pId = adminId;
        }
        if (users.getRole() == 2) {
            pId = users.getParentid();
        }

        System.out.println(starttime);
        SelfShopCoupon selfShopCoupon = null;
        String coupons = "重复的优惠券：";
        for (SelfShopCoupon s : CommExcel.couponList) {

            SelfShopCoupon ssc = selfShopCouponService.selectByCoupon(s.getCoupon(), pId, adminId);

            if (ssc != null) {
                coupons += s.getCoupon() + ",";
                continue;
            }
            try {
                selfShopCoupon = new SelfShopCoupon(Produce.getUUID(), pId, adminId,
                        s.getCoupon(), null, (byte) 0, Produce.getNowDate(), couponGoods,
                        new SimpleDateFormat("yyyy-MM-dd").parse(starttime),
                        new SimpleDateFormat("yyyy-MM-dd").parse(endtime), (byte) 1);
            } catch (ParseException e) {

                e.printStackTrace();
            }
            int resultCode = selfShopCouponService.insertSelective(selfShopCoupon);

            if (resultCode != 1) {
                out.print(s.getCoupon() + "导入时出错");
                return;
            }
        }
        out.print("导入成功," + coupons);
    }


    public void readExcel(HttpServletRequest request, HttpServletResponse response, String file) throws Exception {

        PrintWriter out = response.getWriter();
        if (file == null || CommExcel.EMPTY.equals(file)) {
            out.println("请传入正确的Excel文件");
            return;
        } else {
            String postfix = getPostfix(file);
            if (!CommExcel.EMPTY.equals(postfix)) {
                if (CommExcel.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)) {
                    readXls(request, response, file);
                } else if (CommExcel.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)) {
                    readXlsx(request, response, file);
                }
            } else {
                System.out.println(file + CommExcel.NOT_EXCEL_FILE);
            }
        }
    }

    /**
     * 读取 Excel 2010
     *
     * @param file
     * @return
     * @throws IOException
     */
    public void readXlsx(HttpServletRequest request, HttpServletResponse response, String file) throws Exception {
        System.out.println(CommExcel.PROCESSING + file);
        InputStream is = new FileInputStream(file);
        @SuppressWarnings("resource")
        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
        SelfShopCoupon selfShopCoupon = null;
        // 读取表格
        for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
            XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
            if (xssfSheet == null) {
                continue;
            }
            // 读取行 第二行开始
            for (int rowNum = 2; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
                XSSFRow xssfRow = xssfSheet.getRow(rowNum);
                if (xssfRow != null) {
                    selfShopCoupon = new SelfShopCoupon();
                    XSSFCell cell = xssfRow.getCell(0);
                    //设置单元格类型
                    cell.setCellType(CellType.STRING);
                    //获取单元格数据
                    String coupon = cell.getStringCellValue();

                    selfShopCoupon.setCoupon(coupon);

                    CommExcel.couponList.add(selfShopCoupon);
                }
            }
        }
    }

    /**
     * 读取 Excel 2003-2007
     *
     * @param file
     * @return
     * @throws IOException
     * @throws ParseException
     */
    public void readXls(HttpServletRequest request, HttpServletResponse response, String file) throws IOException, ParseException {
        System.out.println(CommExcel.PROCESSING + file);
        InputStream is = new FileInputStream(file);
        @SuppressWarnings("resource")
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
        SelfShopCoupon selfShopCoupon = null;
        // 读取表格
        for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
            HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
            if (hssfSheet == null) {
                continue;
            }
            // 读取行
            for (int rowNum = 2; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
                HSSFRow hssfRow = hssfSheet.getRow(rowNum);
                if (hssfRow != null) {
                    selfShopCoupon = new SelfShopCoupon();
                    HSSFCell cell = hssfRow.getCell(0);
                    //设置单元格类型
                    cell.setCellType(CellType.STRING);
                    //获取单元格数据
                    String coupon = cell.getStringCellValue();

                    selfShopCoupon.setCoupon(coupon);

                    CommExcel.couponList.add(selfShopCoupon);
                }
            }
        }
    }

    //Excal 2007-2010 取值
    @SuppressWarnings({"static-access", "deprecation"})
    private String getXValue(XSSFCell xssfRow) {
        if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {
            return String.valueOf(xssfRow.getBooleanCellValue());
        } else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_NUMERIC) {
            return String.valueOf(xssfRow.getNumericCellValue());
        } else {
            return String.valueOf(xssfRow.getStringCellValue());
        }
    }

    //Excal 2003 取值
    @SuppressWarnings({"static-access", "deprecation"})
    private String getHValue(HSSFCell hssfCell) {
        if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
            return String.valueOf(hssfCell.getBooleanCellValue());
        } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
            return String.valueOf(hssfCell.getNumericCellValue());
        } else {
            return String.valueOf(hssfCell.getStringCellValue());
        }
    }


    //判断Excel 2003 或者2007-2010
    public static String getPostfix(String file) {
        if (file == null || CommExcel.EMPTY.equals(file)) {
            return CommExcel.EMPTY;
        }
        if (file.contains(CommExcel.POINT)) {
            return file.substring(file.lastIndexOf(CommExcel.POINT) + 1);
        }
        return CommExcel.EMPTY;
    }


}
